﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Design;
using BizAppFactory.Domain;
using System.ComponentModel;

namespace BizAppFactory.DomainModel.CustomEditors.UniqueConstraintEditor
{

    public class UniqueConstraintEditor : System.Drawing.Design.UITypeEditor
    {
        public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
        {
            if (context != null && context.Instance != null)
            {
                return UITypeEditorEditStyle.Modal;
            }

            return base.GetEditStyle(context);
        }

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context != null && context.Instance != null && provider != null)
            {
                UniqueConstraintForm uniqueConstaintForm = new UniqueConstraintForm();
                uniqueConstaintForm.EditedUniqueConstraint = (UniqueConstraint)context.Instance;
                uniqueConstaintForm.ShowDialog();
            }

            return value;
        }
    }
}
